//
//  SHOAuthProgressView.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/21.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit

class SHOAuthProgressView: UIProgressView {

    var isAnim: Bool = true
    
    var timer: NSTimer?
    
    override init(frame: CGRect) {
        super.init(frame: CGRectMake(0, 64, SCREENW, 2))
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        self.tintColor = UIColor.greenColor()
    }
    
    func startAnim(){
        
        self.progress = 0
        
        self.hidden = false
        
        timer = NSTimer.scheduledTimerWithTimeInterval(1/60, target: self, selector: "valueChange", userInfo: nil, repeats: true)
    }
    
    func stopAnim(){
        
       timer?.invalidate()
    }
    
    func removeView() {
        
        timer?.invalidate()
        removeFromSuperview()
    }
    
    func valueChange(){
        
        if isAnim{
            
            self.progress += 0.05
            
            if self.progress >= 0.95{
                self.progress = 0.95
            }else{
            
                if self.progress == 1{
                
                self.hidden = true
                
                timer?.invalidate()
            }else{
                
                self.progress += 0.05
            }
        }
    }

}
    
    deinit{
        timer?.invalidate()
    }


}
